package com.xiaomi.mapper;

import com.xiaomi.entity.Rule;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RuleMapper {
    @Select("select * from rule_config")
    List<Rule> selectAll();

    @Select("select * from rule_config where battery_type = #{batteryType}")
    List<Rule> selectByBatteryType(String batteryType);
    @Insert("insert into rule_config(rule_code, rule_name, battery_type, condition_json, create_time, update_time) " +
        "values" +
        "(#{ruleCode}, #{ruleName}, #{batteryType}, #{conditionJson}, #{createTime}, #{updateTime})")
    void insert(Rule rule);

    @Select("SELECT * FROM rule_config WHERE rule_id = #{id}")
    Rule selectById(Long id);
    @Delete("delete from rule_config where rule_id = #{id}")
    int deleteById(Long id);

    @Update("update rule_config set rule_name = #{ruleName}, battery_type = #{batteryType}, condition_json = #{conditionJson}, update_time = #{updateTime} where rule_id = #{ruleId}")
    int updateById(Rule rule);
}
